//
//  SettingThemeViewController.m
//  HandyDialer
//
//	Developed by Team Synergy
//  Created by Jacky Li on 11-11-15.
//  Coders: Jacky Li and Jordan Tseng 
//  Graphic Designer: Derek Fong
//  Developers: Brad Lisson, Derek Fong, Jacky Li, Jeremy Gangoso, Jordan Tseng
//  Copyright HandyDialer 2011. All rights reserved.


#import "SettingThemeViewController.h"

@implementation SettingThemeViewController
@synthesize  highlightArea;
@synthesize backgroundArea;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}


#pragma mark - View lifecycle

- (void)dealloc {
	[highlightArea release];
    [super dealloc];
}

- (void)viewDidLoad {
    
    counter = 0;
	defaults = [NSUserDefaults standardUserDefaults];
    speed = [defaults floatForKey:@"Speed"];
	highlightColor= [defaults stringForKey:@"Highlight"];
	themeColor = [defaults stringForKey:@"Theme"];
    [backgroundArea setImage:[UIImage imageNamed: [themeColor stringByAppendingString:@"_theme_default.png"]]];
	[super viewDidLoad];
    
}

- (void)viewDidAppear:(BOOL)animated
{
    defaults = [NSUserDefaults standardUserDefaults];
    speed = [defaults floatForKey:@"Speed"];
	highlightColor= [defaults stringForKey:@"Highlight"];
	themeColor = [defaults stringForKey:@"Theme"];
    [backgroundArea setImage:[UIImage imageNamed: [themeColor stringByAppendingString:@"_theme_default.png"]]];
	if (uniTimer == nil)
		uniTimer = [NSTimer scheduledTimerWithTimeInterval:(speed) target:self selector:@selector(optionChange) userInfo:nil repeats:YES];
	[super viewDidAppear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[uniTimer invalidate];
	uniTimer = nil;
	[super viewDidDisappear:animated];
}

- (IBAction)switchView:(id)sender
{
	switch (counter)
	{
		case 1:
		{
			[defaults setObject:@"steel" forKey:@"Theme"];
			[defaults synchronize];
			counter = 0;
			[self dismissModalViewControllerAnimated:NO];
			break;
		}
		case 2:
		{
			[defaults setObject:@"navy" forKey:@"Theme"];
			[defaults synchronize];
			counter = 0;
			[self dismissModalViewControllerAnimated:NO];
			break;
		}
		case 3:
		{
			[defaults setObject:@"orange" forKey:@"Theme"];
			[defaults synchronize];
			counter = 0;
			[self dismissModalViewControllerAnimated:NO];
			break;
		}
		case 4:
		{
			[defaults setObject:@"white" forKey:@"Theme"];
			[defaults synchronize];
			counter = 0;
			[self dismissModalViewControllerAnimated:NO];
			break;
		}
		case 5:
		{
			counter = 0;
			[self dismissModalViewControllerAnimated:NO];
			break;
		}
	}
	
}

- (void)highlightChange:(NSString *)picture
{
    UIImage *image = [UIImage imageNamed: picture];
    [highlightArea setImage:image];
	
}

// Decides which screen to go to
-(void)optionChange 
{
    
    if (counter == 5)
    {
        counter = 0;
    }
    counter += 1;
    NSString *next = highlightColor;
	next = [next stringByAppendingString:@"_color_"];  
	next = [next stringByAppendingString:[NSString stringWithFormat:@"%d", counter]];
	next = [next stringByAppendingString:@".png"];
	[self highlightChange:next];
}

@end
